import React from 'react'
import ReactDOM from 'react-dom'
import { SignaturePad } from '.'

function openSignatuerPad (callback) {
    const div = document.createElement('div')

    function confirm (data) {
        ReactDOM.unmountComponentAtNode(div)
        callback(data)
    }

    function cancel (data) {
        ReactDOM.unmountComponentAtNode(div)
        callback(null)
    }

    ReactDOM.render(
        <SignaturePad isOpen onConfirm={confirm} onCancel={cancel} />,
        div
    )

    return cancel
}

export { openSignatuerPad }
